<template>
  <el-container class="home-container">
    <el-aside width="200px" class="sidebar">
      <!-- Logo和系统名称区域 -->
      <div class="sidebar-header">
        <img src="/images/生成校园小程序 logo.png" alt="系统Logo" class="app-logo" />
        <div class="app-info">
          <h3 class="app-name">校园助手</h3>
          <p class="app-desc">校园互助平台</p>
        </div>
      </div>
      
      <el-menu default-active="1" class="el-menu-vertical-demo" @select="handleMenuSelect">
        <!-- 交流广场 - 更换以确保可用的图标 -->
        <el-menu-item index="1" class="custom-menu-item">
          <ChatRound class="custom-icon" />
          <span class="menu-text">交流广场</span>
        </el-menu-item>

        <!-- 好友列表 -->
        <el-menu-item index="2" class="custom-menu-item">
          <UserFilled class="custom-icon" />
          <span class="menu-text">好友列表</span>
        </el-menu-item>

        <!-- 接单大厅 -->
        <el-menu-item index="3" class="custom-menu-item">
          <ShoppingBag class="custom-icon" />
          <span class="menu-text">帮帮大厅</span>
        </el-menu-item>

        <!-- 个人中心 -->
        <el-menu-item index="4" class="custom-menu-item">
          <Avatar class="custom-icon" />
          <span class="menu-text">个人中心</span>
        </el-menu-item>
      </el-menu>
      
      <!-- 退出登录按钮 -->
      <div class="logout-section">
        <el-button @click="handleLogout" class="logout-btn" type="danger" plain>
          <SwitchButton class="logout-icon" />
          <span>退出登录</span>
        </el-button>
      </div>
    </el-aside>
    <el-main class="main-content">
      <!-- 顶部通知栏 -->
      <div class="top-notification-bar">
        <div class="notification-wrapper">
          <NotificationCenter />
        </div>
      </div>
      <!-- 添加统一的内容容器 -->
      <div class="content-container">
        <component :is="currentComponent"></component>
      </div>
    </el-main>
  </el-container>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
// 导入模块组件
import Square from './modules/Square.vue';
import FriendsList from './modules/FriendsList.vue';
import TaskHall from './modules/TaskHall.vue';
import Profile from './modules/Profile.vue';
// 导入通知中心组件
import NotificationCenter from '../components/NotificationCenter.vue';
// 导入图标
import { ChatRound, UserFilled, ShoppingBag, Avatar, SwitchButton } from '@element-plus/icons-vue';

const router = useRouter();

// 设置默认显示组件
const currentComponent = ref(Square);

// 菜单切换逻辑
const handleMenuSelect = (index) => {
  switch(index) {
    case '1':
      currentComponent.value = Square;
      break;
    case '2':
      currentComponent.value = FriendsList;
      break;
    case '3':
      currentComponent.value = TaskHall;
      break;
    case '4':
      currentComponent.value = Profile;
      break;
  }
};

// 退出登录功能
const handleLogout = async () => {
  try {
    await ElMessageBox.confirm(
      '确定要退出登录吗？',
      '退出确认',
      {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }
    );
    
    // 清除本地存储的token
    localStorage.removeItem('token');
    
    // 显示成功消息
    ElMessage.success('已退出登录');
    
    // 跳转到登录页面，并清除历史记录
    router.replace('/login');
  } catch {
    // 用户取消退出
  }
};
</script>

<style scoped>
/* 修改侧边栏和主内容区布局 */
.home-container {
  height: 100vh; 
  display: flex; 
  overflow: hidden;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.el-aside {
  background: linear-gradient(180deg, #667eea 0%, #764ba2 100%);
  box-shadow: 4px 0 20px rgba(0,0,0,0.1);
  border-right: none;
  border-radius: 0 25px 25px 0;
  z-index: 1;
  flex-shrink: 0;
  position: relative;
  margin: 10px 0 10px 10px;
}

/* 侧边栏头部样式 */
.sidebar-header {
  background: rgba(255,255,255,0.1);
  backdrop-filter: blur(10px);
  padding: 30px 20px;
  text-align: center;
  border-bottom: 1px solid rgba(255,255,255,0.2);
  border-radius: 0 25px 0 0;
}

/* 应用信息样式 */
.app-info {
  margin-top: 15px;
}

.app-name {
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 8px 0;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
  letter-spacing: 1px;
}

.app-desc {
  color: rgba(255,255,255,0.8);
  font-size: 13px;
  margin: 0;
  font-weight: 300;
  letter-spacing: 0.5px;
}

/* 修改主内容区背景和容器样式 */
.el-main.main-content {
  padding: 0;
  height: 100%;
  overflow-y: auto;
  box-sizing: border-box;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  flex: 1;
  margin: 10px 10px 10px 0;
  border-radius: 25px 0 0 25px;
  box-shadow: -4px 0 20px rgba(0,0,0,0.1);
}

/* 顶部标题栏样式 */
:deep(.el-page-header) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  color: #ffffff !important;
  border-bottom: 1px solid rgba(255,255,255,0.2) !important;
  border-radius: 25px 0 0 0 !important;
}

/* Square组件中的顶部区域样式 */
:deep(.content-header) {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
  color: #ffffff !important;
  padding: 20px 30px !important;
  border-bottom: 1px solid rgba(255,255,255,0.2) !important;
  border-radius: 25px 0 0 0 !important;
  backdrop-filter: blur(10px) !important;
}

:deep(.content-header h2) {
  color: #ffffff !important;
  margin: 0 !important;
}

    .content-container {
      max-width: none;
      margin: 0;
      width: 100%;
      height: 100%;
    }

/* 卡片通用样式 */
.content-card {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.04);
  padding: 20px;
  margin-bottom: 20px;
  transition: box-shadow 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.content-card:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* 顶部通知栏样式 */
.top-notification-bar {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 10px 20px;
  border-radius: 25px 0 0 0;
  border-bottom: 1px solid rgba(255,255,255,0.2);
}

.notification-wrapper {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

/* Logo样式 */
.app-logo {
  width: 70px;
  height: 70px;
  display: block;
  margin: 0 auto 15px;
  object-fit: contain;
  border-radius: 50%;
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(10px);
  border: 2px solid rgba(255,255,255,0.3);
  box-shadow: 0 8px 25px rgba(0,0,0,0.2);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.app-logo:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 35px rgba(0,0,0,0.3);
}

/* 图标样式优化 */
::v-deep .custom-icon {
  width: 20px !important;
  height: 20px !important;
  margin-right: 12px !important;
  vertical-align: middle !important;
  display: inline-block !important;
  color: rgba(255,255,255,0.9) !important;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* 菜单项样式优化 */
:deep(.el-menu-item) {
  height: 50px !important;
  line-height: 50px !important;
  padding: 0 20px !important;
}

/* 菜单文字样式 */
:deep(.menu-text) {
  display: inline-block;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.5px;
}

/* 菜单样式优化 */
::v-deep .el-menu-vertical-demo {
  background-color: transparent !important;
  border-right: none !important;
  padding: 10px;
}

::v-deep .el-menu-vertical-demo .el-menu-item {
  background: rgba(255,255,255,0.1) !important;
  color: #ffffff !important;
  border-radius: 15px !important;
  margin: 8px 0 !important;
  backdrop-filter: blur(5px) !important;
  border: 1px solid rgba(255,255,255,0.2) !important;
  transition: all 0.3s ease !important;
}

::v-deep .el-menu-vertical-demo .el-menu-item:hover {
  background: rgba(255,255,255,0.2) !important;
  color: #ffffff !important;
  transform: translateX(5px) !important;
  box-shadow: 0 5px 15px rgba(0,0,0,0.2) !important;
}

/* 增强激活状态样式 */
::v-deep .el-menu-vertical-demo .el-menu-item.custom-menu-item.is-active {
  background: rgba(255,255,255,0.3) !important;
  color: #ffffff !important;
  border-left: 4px solid #ffffff !important;
  font-weight: 600 !important;
  box-shadow: 0 8px 25px rgba(0,0,0,0.3) !important;
}

/* 内容卡片样式优化 */
.content-card {
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
  padding: 25px;
  margin: 20px;
  border: 1px solid rgba(255,255,255,0.2);
  transition: all 0.3s ease;
}

.content-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 15px 35px rgba(0,0,0,0.15);
}

/* 退出登录按钮样式 */
.logout-section {
  position: absolute;
  bottom: 20px;
  left: 20px;
  right: 20px;
}

.logout-btn {
  width: 100%;
  height: 45px;
  background: rgba(255, 255, 255, 0.1) !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  color: #ffffff !important;
  border-radius: 15px !important;
  backdrop-filter: blur(5px) !important;
  transition: all 0.3s ease !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.2) !important;
  border-color: rgba(255, 255, 255, 0.5) !important;
  transform: translateY(-2px) !important;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2) !important;
}

.logout-icon {
  width: 16px !important;
  height: 16px !important;
}
</style>